<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/AdminTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="title">
        News management
    </ui:define>

    <ui:define name="content">
        <p:growl id="growl1" showDetail="true" life="3000" /> 
            <h:form id="form">
                
            <h:panelGrid columns="1">

                <h:panelGrid columns="1">

                    <p:dataTable var="newsvar" value="#{newsMBean.getNewsList}" rowKey="#{newsvar.newsID}" paginator="true" rows="10"
                                 selection="#{newsMBean.news}" selectionMode="single" filteredValue="#{newsMBean.filteredNews}" id="newsTable">

                        <p:ajax event="rowSelect" update=":form:display" oncomplete="newsDialog.show()" />

                        <f:facet name="header">
                            List of News
                        </f:facet>

                        <p:column headerText="NewsID" sortBy="#{newsvar.newsID}" filterBy="#{newsvar.newsID}" id="newsID">
                            #{newsvar.newsID}
                        </p:column>

                        <p:column headerText="News Title" sortBy="#{newsvar.newsTitle}" filterBy="#{newsvar.newsTitle}" id="newsName">
                            #{newsvar.newsTitle}
                        </p:column>

                        <p:column headerText="News Content" sortBy="#{newsvar.newsContents}" filterBy="#{newsvar.newsContents}" id="newsContent">
                            #{newsvar.newsContents}
                        </p:column>

                    </p:dataTable>



                    <p:dialog header="News Detail" widgetVar="newsDialog" resizable="true"  
                               showEffect="explode" hideEffect="explode">

                        <h:panelGrid id="display">

                            <f:facet name="header">
                                <h:outputText value="Hinh anh" />
                            </f:facet>

                            <h:outputText value="NewsID" />
                            <h:inputText value="#{newsMBean.news.newsID}" id="newsID"/>                     

                            <h:outputText value="News Title" />
                            <h:inputText value="#{newsMBean.news.newsTitle}" id="newsTitle"/>

                            <h:outputText value="News Content" />

                            <p:editor id="newsContent" value="#{newsMBean.news.newsContents}" width="600"/>

                            <p:commandButton value="Delete" action="#{newsMBean.removeNews()}" oncomplete="newsDialog.hide()" update=":form:newsTable, :growl1"/>
                            <p:commandButton value="Update" action="#{newsMBean.editNews(newsMBean.news)}" oncomplete="newsDialog.hide()" update=":form:newsTable, :growl1"/>

                        </h:panelGrid>
                    </p:dialog>    

                </h:panelGrid>

            </h:panelGrid>

        </h:form>
        <h:form>
            <h:panelGrid columns="1">

                    <p:commandButton id="viewButton" value="Add the lastest news" 
                                     oncomplete="addNewsDialog.show()"/> 

                    <p:dialog id="dialogadd" header="Add New Type of News" widgetVar="addNewsDialog" resizable="false"  
                              showEffect="fade" hideEffect="fade">  
                        <h:panelGrid id="displayAdd">  
                            <p:outputLabel value="NewsID:" for="nID"/>
                            <p:inputText id="nID" value="#{newsMBean.other.newsID}" title="NewsID" required="true"/>                    
                            <p:message for="nID"/>

                            <p:outputLabel value="News Title:" for="nTitle"/>
                            <p:inputText id="nTitle" value="#{newsMBean.other.newsTitle}" title="News Title" required="true" />                    
                            <p:message for="nTitle"/>

                            <p:outputLabel value="News Content:" for="nContent"/>

                            <p:editor id="nContent" value="#{newsMBean.other.newsContents}" width="600"/> 
                            <p:message for="nContent"/>
                        </h:panelGrid>  
                        <p:commandButton value="Create" action="#{newsMBean.createNews()}" oncomplete="addNewsDialog.hide()" update=":growl1, :form:newsTable"/>                      
                    </p:dialog>

                </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>
